<?php

namespace app\admin\controller;

use liang\MicroEngine;
use app\admin\logic\Admin as AdminLogic;

class Index extends Base
{
    /**
     * 后台主页
     */
    public function index()
    {
        if (MicroEngine::isMicroEngine()) {
            // 微擎
            global $_W;
            $username = $_W['user']['username'];
            $logout = '/web/index.php?c=user&a=logout&';
        } else {
            // 独立版
            $aid = intval(session('aid'));
            $username = AdminLogic::getUsernameById($aid);
            $logout = u('logout');
        }
        return view('', compact('username', 'logout'));
    }

    /**
     * 控制台
     */
    public function console()
    {
        return view();
    }

    /**
     * 退出登陆 (独立版)
     */
    public function logout()
    {
        session('aid', null);
        return redirect(u('login/index'));
    }
}
